package system

import (
	"context"

	"go_admin/api/system/v1"
	"go_admin/internal/database/system/model/dto"
	"go_admin/internal/database/system/model/entity"
	"go_admin/internal/service"
)

func (c *ControllerV1) UserMenus(ctx context.Context, req *v1.UserMenusReq) (res *v1.UserMenusRes, err error) {
	var (
		permissions []string
		menuList    []*dto.UserMenus
	)
	userId := service.Context().GetUserId(ctx)
	menuList, permissions, err = service.SysUser().GetAdminRules(ctx, userId)
	res = &v1.UserMenusRes{
		MenuList:    menuList,
		Permissions: permissions,
	}
	return
}
func (c *ControllerV1) UserList(ctx context.Context, req *v1.UserListReq) (res *v1.UserListRes, err error) {
	var (
		total    interface{}
		userList []*entity.SysUser
	)
	res = new(v1.UserListRes)
	total, userList, err = service.SysUser().List(ctx, req)
	if err != nil || total == 0 {
		return
	}
	res.Total = total
	res.UserList, err = service.SysUser().GetUsersRoleDept(ctx, userList)
	return
}
func (c *ControllerV1) UserGetParams(ctx context.Context, req *v1.UserGetParamsReq) (res *v1.UserGetParamsRes, err error) {
	res = new(v1.UserGetParamsRes)
	res.RoleList, err = service.SysRole().GetRoleList(ctx)
	if err != nil {
		return
	}
	res.Posts, err = service.SysPost().GetUsedPost(ctx)
	return
}
func (c *ControllerV1) UserAdd(ctx context.Context, req *v1.UserAddReq) (res *v1.UserAddRes, err error) {
	err = service.SysUser().Add(ctx, req)
	return
}
func (c *ControllerV1) UserEdit(ctx context.Context, req *v1.UserEditReq) (res *v1.UserEditRes, err error) {
	err = service.SysUser().Edit(ctx, req)
	return
}
func (c *ControllerV1) UserGetEdit(ctx context.Context, req *v1.UserGetEditReq) (res *v1.UserGetEditRes, err error) {
	res, err = service.SysUser().GetEditUser(ctx, req.Id)
	return
}
func (c *ControllerV1) UserResetPwd(ctx context.Context, req *v1.UserResetPwdReq) (res *v1.UserResetPwdRes, err error) {
	err = service.SysUser().ResetUserPwd(ctx, req)
	return
}
func (c *ControllerV1) UserStatus(ctx context.Context, req *v1.UserStatusReq) (res *v1.UserStatusRes, err error) {
	err = service.SysUser().ChangeUserStatus(ctx, req)
	return
}
func (c *ControllerV1) UserDelete(ctx context.Context, req *v1.UserDeleteReq) (res *v1.UserDeleteRes, err error) {
	err = service.SysUser().Delete(ctx, req.Ids)
	return
}
func (c *ControllerV1) UserGetByIds(ctx context.Context, req *v1.UserGetByIdsReq) (res *v1.UserGetByIdsRes, err error) {
	res = new(v1.UserGetByIdsRes)
	res.List, err = service.SysUser().GetUsers(ctx, req.Ids)
	return
}
